/**
 * @param {number} n
 * @return {string}
 */
var countAndSay = function (n) {
  if (n === 1)
    return '1'
  let res = '1'
  for (let i = 2; i <= n; i++) {
    res = get(res)
  }
  return res;
};
function get(c) {
  let temp = 1;
  let res = ''
  for (let i = 0; i < c.length; i++) {
    if (c[i] === c[i + 1]) {
      temp++;
      if (i + 1 === c.length - 1) {
        res += `${temp}${c[i]}`
        break;
      }
    } else {
      res += `${temp}${c[i]}`
      temp = 1;
    }
  }
  return res;
}
console.log(countAndSay(1));
console.log(countAndSay(2));
console.log(countAndSay(4));
// console.log(get('21'));
// console.log(get('1211'));
// console.log(get('3322251'));